#!/usr/bin/perl -w

# This module opens a flash window for one second when page is changed.
# Run and stop it from fvwm as:
#     Module /path/to/module-flash
#     KillModule /path/to/module-flash

use lib `fvwm-perllib dir`;
use FVWM::Module;

# choose the flash command (install osd_cat from xosd, it is nice)
my $flash_cmd = -x '/usr/bin/osd_cat'
	? "osd_cat -f 12x24 -A center -p middle -l 1 -s 2 -d 2 -c yellow"
	: "xmessage -name FlashWindow -bg rgb:50/a0/d0 -fg white -center "
	. "-timeout 1 -buttons '' -xrm '*Margin: 12' -xrm '*cursorName: none' "
	. "-xrm '*borderWidth: 2' -xrm '*borderColor: rgb:f0/f0/a0' -file -";

my $module = new FVWM::Module(Debug => 0);

# show flash on every page switching
my $page_tracker = $module->track("PageInfo");

$page_tracker->observe(sub {
	my ($module, $tracker, $info) = @_;
	$module->send(
		"Exec killall osd_cat xmessage 2>/dev/null; " .
		"echo 'Desk $info->{desk_n} " .
		"($info->{page_nx}, $info->{page_ny})' | $flash_cmd"
	);
});

# make the FlashWindow special: OnTop, without border, without focus and so on
$module->send("Style FlashWindow UsePPosition, NoTitle, NoHandles, BorderWidth 10, StaysOnTop, WindowListSkip, NeverFocus");

# finally enter event loop
$module->event_loop;
